package controllers

import (
	"gameTest/common"
	"gameTest/datamodels"
	"gameTest/services"
	"github.com/kataras/iris"
	"strconv"
)

type ProductController struct {
	Ctx iris.Context
	ProductService services.IProductService
}

func (c *ProductController) GetList() datamodels.Result {
	pageStr := c.Ctx.FormValue("page")
	if pageStr == "" {
		pageStr = "1"
	}
	page, err := strconv.ParseInt(pageStr, 10, 64)
	if err != nil {
		c.Ctx.Application().Logger().Debug(err)
	}
	if page == 0 {
		page = 1
	}

	resultList, err := c.ProductService.GetProductList("1 = 1", page, 10)
	if err != nil {
		return common.BuildResult(400, "失败", err)
	}
	return common.BuildResult(200, "成功", resultList)
}
